﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Needle.Utils.Extensions
{
    /// <summary></summary>
    public static class IntegerExtensions
    {

        /// <summary></summary>
        public static int Thousand(this int value)
        {
            return value * 1000;
        }

        /// <summary></summary>
        public static int Million(this int value)
        {
            return value.Thousand() * 1000;
        }

        /// <summary></summary>
        public static int Billion(this int value)
        {
            return value.Million() * 1000;
        }

        /// <summary></summary>
        public static int KiloByte(this int value)
        {
            return value * 1024 ;
        }

        /// <summary></summary>
        public static int MegaByte(this int value)
        {
            return value * 1024 * 1024;
        }

        /// <summary></summary>
        public static int GigaByte(this int value)
        {
            return value * 1024 * 1024 * 1024;
        }

        /// <summary></summary>
        public static IEnumerable<object> Times(this int count, Action action)
        {
            for (int i = 0; i < count; i++)
            {
                action();
                yield return null;
            }
        }

        /// <summary></summary>
        public static IEnumerable<T> Times<T>(this int count, Action<T> action, IEnumerable<T> items)
        {
            int x = 0;
            if (x >= count)
                yield break;
            foreach (var item in items)
            {
                action(item);
                yield return item;
                x++;
                if (x == count)
                    break;
            }
        }

        /// <summary></summary>
        public static IEnumerable<T> ItemsFrom<T>(this int count, IEnumerable<T> items)
        {
           return count.Times((T item) => { }, items);
        }

        /// <summary></summary>
        public static IEnumerable<int> To(this int from, int to)
        {
            if (from == to)
                yield break;
         
            int inc = Math.Sign(to - from);
            for (int i = from; i != to; i += inc)
                yield return i;
        }

        /// <summary></summary>
        public static TimeSpan Seconds(this int value)
        {
            return TimeSpan.FromSeconds(value);
        }

        /// <summary></summary>
        public static TimeSpan Minutes(this int value)
        {
            return TimeSpan.FromMinutes(value);
        }

        /// <summary></summary>
        public static TimeSpan Hours(this int value)
        {
            return TimeSpan.FromHours(value);
        }

        /// <summary></summary>
        public static TimeSpan Days(this int value)
        {
            return TimeSpan.FromDays(value);
        }

        /// <summary></summary>
        public static TimeSpan Milliseconds(this int value)
        {
            return TimeSpan.FromMilliseconds(value);
        }
    
    }
}
